package com.ltmonitor.web.mq;

import com.ltmonitor.entity.GPSRealData;
import com.ltmonitor.service.IRealDataService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;


public class GPSRealDataTopicMessageListener implements MessageListener {
	private static Logger logger = Logger.getLogger(GPSRealDataTopicMessageListener.class);
	@Autowired
	private IRealDataService realDataService;

	// 当收到消息后，自动调用该方法
	@Override
	public void onMessage(Message message) {
		
		ObjectMessage tm = (ObjectMessage) message;
		try {
			GPSRealData rd = (GPSRealData)tm.getObject();
			realDataService.update(rd);
			//logger.error("QueueMessageListener监听到了文本消息：\t" + tm.getObject());
			//HelloHandler.broadcast(new TextMessage("报警了"));
			// do something ...
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
	}

}
